package com.ssy.lingxi.product.entity;

import com.fasterxml.jackson.annotation.JsonManagedReference;
import lombok.Getter;
import lombok.Setter;

import javax.persistence.*;
import java.io.Serializable;
import java.util.List;

/**
 * 订单会员商品已售实体类
 * @author jw.chen
 * @version 2.0.0
 * @date 2020/9/4
 */
@Getter
@Setter
@Entity
@Table(schema = "public", name = "product_order_commodity", indexes = {@Index(name = "product_order_commodity_commodity_id_idx", columnList = "commodityId")})
public class OrderCommodity implements Serializable {
    private static final long serialVersionUID = 7565701756623347526L;
    /**
     * 主键id
     */
    @Id
    @GeneratedValue(strategy= GenerationType.SEQUENCE, generator="order_commodity_seq")
    @SequenceGenerator(sequenceName="product_order_commodity_seq", name="order_commodity_seq",allocationSize = 1)
    private Long id;

    /**
     * 商品类型：1-会员商品; 2-渠道商品
     */
    @Column(columnDefinition = "int")
    private Integer type;

    /**
     * 商品id
     */
    @Column(columnDefinition = "int8", nullable = false)
    private Long commodityId;

    /**
     * 商品已售数量
     */
    @JsonManagedReference
    @OneToMany(mappedBy = "orderCommodity", cascade={CascadeType.PERSIST, CascadeType.MERGE, CascadeType.REMOVE})
    private List<OrderCommoditySold> orderCommoditySoldList;

}
